package apk.yoursms.menu;

import android.content.Context;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.widget.PopupWindow;
import apk.yoursms.R;

public class Menu {

    private Context mContext;
    private PopupWindow popupWindow = null;
    private LayoutInflater mLayoutInflater = null;

    // public values
    public boolean isShow;

    public Menu(Context context, LayoutInflater lo) {
	mContext = context;
	mLayoutInflater = lo;
    }

    public boolean isShow() {
	return isShow;
    }

    public synchronized void hide() {
	isShow = false;
	if (popupWindow != null) {
	    popupWindow.dismiss();
	    popupWindow = null;
	}
	return;
    }

    public synchronized void show(View v) {
	isShow = true;
	if (popupWindow != null)
	    return;

	Display display = ((WindowManager) mContext
		.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
	View mView = mLayoutInflater.inflate(R.layout.menu, null);
	popupWindow = new PopupWindow(mView, LayoutParams.FILL_PARENT,
		LayoutParams.WRAP_CONTENT, false);
	popupWindow.setAnimationStyle(android.R.style.Animation_Dialog);
	popupWindow.setWidth(display.getWidth());
	popupWindow.showAtLocation(v, Gravity.BOTTOM, 0, 0);	
    }

}
